{% load base_tags %}
{% load static from staticfiles %}

{% if DEBUG_STATIC %}
<script src="{% static "lib/js/angular.js" %}"></script>
<script src="{% static "lib/js/angular-cookies.js" %}"></script>
<script src={% static "lib/js/angular-sanitize.min.js" %}></script>
<script src="{% static "lib/js/angular-openlayers-directive.min.js" %}"></script>
{% endif %}

{% if include_spatial == 'true' %}
<style>
  .filter-map-container {  /* filter map */
    height: 300px;
  }
</style>

{% endif %}
{% block search_script_loading %}
<script src="{% static "geonode/js/search/explore.js" %}"></script>
<script src="{% static "geonode/js/search/search.js" %}"></script>
<script src="{% static "geonode/js/search/cart.js" %}"></script>
{% endblock search_script_loading %}
<script type="text/javascript">
  $("body").attr('ng-controller', 'geonode_search_controller');
  {% block search_scripts_endpoints %}
  CATEGORIES_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='categories' %}';
  GROUP_CATEGORIES_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='groupcategory' %}';
  KEYWORDS_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='keywords' %}';
  H_KEYWORDS_ENDPOINT = '{% url 'h_keywords_api' %}';
  var enable_thesauri = false;
  {% if THESAURI_FILTERS %}
    var enable_thesauri = true;
    T_KEYWORDS_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='thesaurus/keywords' %}';
  {% endif %}
  REGIONS_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='regions' %}';
  OWNERS_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='owners' %}';
  GROUPS_ENDPOINT = '{% url 'api_dispatch_list' api_name='api' resource_name='groups' %}';
  HAYSTACK_SEARCH = "{{ HAYSTACK_SEARCH }}".toLowerCase() === "true";
  HAYSTACK_FACET_COUNTS = "{{ HAYSTACK_FACET_COUNTS }}".toLowerCase() === "true";
  CLIENT_RESULTS_LIMIT = {{ CLIENT_RESULTS_LIMIT }};
 {% endblock %}
  // Register autocomplete for text filters
  $(document).ready(function() {
    window.autocomplete = new Autocomplete({
      form_btn: '#text_search_btn',
      form_submit: null,
      form_selector: '#text-search-autocomplete',
      input_selector: '#text_search_input',
      container_selector: '#text-search-container'
    })
    window.autocomplete.setup()
  })

  // Register autocomplete for region filters
  $(document).ready(function() {
    window.autocomplete = new Autocomplete({
      form_btn: '#region_search_btn',
      form_submit: null,
      form_selector: '#region-search-autocomplete',
      input_selector: '#region_search_input',
      container_selector: '#region-search-container',
      url: AUTOCOMPLETE_URL_REGION
    })
    window.autocomplete.setup()
  })

  {% get_context_resourcetype as pathc %}
        {% if pathc == "layers" %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_layer"%}';
        {% elif pathc == "maps" %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_map" %}';
        {% elif pathc == "documents" %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_document" %}';
        {% elif pathc == "search" %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_base" %}';
        {% elif pathc == "people" %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_profile" %}';
        {% elif pathc == "groups/categories" %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_category" %}';
        {% elif pathc == "groups" %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_groups" %}';
        {% else %}
                AUTOCOMPLETE_URL_RESOURCEBASE = '{% url "autocomplete_base" %}';
        {% endif %}
  AUTOCOMPLETE_URL_REGION = '{% url "autocomplete_region" %}';

  var module = angular.module('search', ['geonode_main_search', 'cart']);
  module.constant('Configs', {
    url: SEARCH_URL
  });

  var deps = ['search'];
  {% if include_spatial == 'true' %}
  deps.push('openlayers-directive');
  {% endif %}
  angular.bootstrap(document, deps);
</script>
